package com.example.electronicmall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.electronicmall.R;
import com.example.electronicmall.bean.RightModel;

import java.util.List;

/**
 * Created by
 * Time: 19:29
 * Author: Lenovo
 */
public class CommodityRightAdapter extends RecyclerView.Adapter<CommodityRightAdapter.rightHolder> {
    private Context context;
    private List<RightModel> rightbeanList;
    private onItemRightClick onItemRightClick;

    public CommodityRightAdapter(Context context) {
        this.context = context;
    }


    public void setRightbeanList(List<RightModel> rightbeanList) {
        this.rightbeanList = rightbeanList;
    }

    public void setOnItemRightClick(CommodityRightAdapter.onItemRightClick onItemRightClick) {
        this.onItemRightClick = onItemRightClick;
    }

    @NonNull
    @Override
    public rightHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        return new rightHolder(LayoutInflater.from(context).inflate(R.layout.claddfiyright_list_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull  rightHolder holder, int position) {

        holder.rname.setText(rightbeanList.get(position).getRightName());
        holder.icon.setImageBitmap(rightbeanList.get(position).getRightIcon());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onItemRightClick!=null){
                    onItemRightClick.onItemClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return null==rightbeanList?0 :rightbeanList.size();
    }

    class rightHolder extends RecyclerView.ViewHolder{

        TextView rname;
        ImageView icon;
        public rightHolder(@NonNull View itemView) {
            super(itemView);
            rname=itemView.findViewById(R.id.right_tv);
            icon=itemView.findViewById(R.id.im_right);
        }
    }

    public interface onItemRightClick{
        void onItemClick(int position);
    }
}
